package com.muyan.mq.core.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyan.mq.core.bean.MqLogs;
import com.muyan.mq.core.dao.MqLogsDao;
import com.muyan.mq.core.param.MqLogsParam;
import com.muyan.mq.core.service.MqLogsService;
import com.muyan.sys.common.exception.ServiceException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
**mq日志
*/

@Service
public class MqLogsServiceImpl extends ServiceImpl<MqLogsDao, MqLogs> implements MqLogsService {


    @Autowired
    private MqLogsDao mqLogsDao;





    @Override
    public void updateByParam(MqLogsParam param) {
        MqLogs mqLogs=mqLogsDao.selectById(param.getId());
        if(mqLogs==null){
          throw   new ServiceException("该记录不存在");
        }
        BeanUtils.copyProperties(param,mqLogs);
        mqLogsDao.updateById(mqLogs);
    }

    @Override
    public void saveByParam(MqLogsParam param) {
        MqLogs mqLogs=new MqLogs();
        MqLogs dbLogs= mqLogsDao.selectByMqId(param.getMqId());
        if(dbLogs!=null){
            return;
        }
        BeanUtils.copyProperties(param,mqLogs);
        mqLogs.setCreateTime(new Date());
       mqLogsDao.insert(mqLogs);
    }
    @Override
    public void deleteStatus(Long id) {
        UpdateWrapper<MqLogs> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id).set("deleted",1);
        mqLogsDao.update(null, updateWrapper);
    }
}